package com.zy.web.controller.bs;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zy.entity.bs.NoticeType;
import com.zy.pojo.query.bs.NoticeTypeQuery;
import com.zy.pojo.vos.common.PageVo;
import com.zy.pojo.vos.common.ResultVo;
import com.zy.service.bs.NoticeTypeService;
import com.zy.web.controller.base.BaseController;
import com.zy.web.utils.ResultUtil;

import java.io.Serializable;

@RequestMapping({"bs/noticeType","m/bs/noticeType"})
@Controller
public class NoticeTypeController extends BaseController {

	@Autowired
	private NoticeTypeService noticeTypeService;

	/**
	 * 分页
 	 * 
 	 * @param noticeTypeQuery
	 * @param start
	 * @param limit
	 * @return
	 */
	@RequestMapping("pageNoticeType")
	@ResponseBody
	public PageVo pageNoticeType(NoticeTypeQuery noticeTypeQuery, Integer start, Integer limit) {
		return this.noticeTypeService.pageNoticeType(noticeTypeQuery, start, limit);
	}

	/**
	 * 新增
	 * 
	 * @param noticeType
	 * @return
	 */
	@RequestMapping(value = "saveNoticeType", method = RequestMethod.POST)
	@ResponseBody
	public ResultVo saveNoticeType(NoticeType noticeType) {
		try {
			noticeType.setCreateUserId(super.getCurrentUser().getId());
			this.noticeTypeService.saveNoticeType(noticeType);
			return ResultUtil.success();
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}
	
	/**
	 * 更新
	 * 
	 * @param noticeType
	 * @return
	 */
	@RequestMapping(value = "updateNoticeType", method = RequestMethod.POST)
	@ResponseBody
	public ResultVo updateNoticeType(NoticeType noticeType) {
		try {
			noticeType.setModifyUserId(super.getCurrentUser().getId());
			this.noticeTypeService.updateNoticeType(noticeType);
			return ResultUtil.success();
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}

	/**
	 * 删除
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "removeNoticeType", method = RequestMethod.POST)
	@ResponseBody
	public ResultVo removeNoticeType(long id) {
		try {
			this.noticeTypeService.removeNoticeType(id);
			return ResultUtil.success();
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}

	/**
	 * 恢复
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "recover", method = RequestMethod.POST)
	@ResponseBody
	public ResultVo recover(long id) {
		try {
			this.noticeTypeService.recover(id);
			return ResultUtil.success();
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}

	/**
	 * 获取公告类型
	 * @return
	 */
	@RequestMapping(value = "front/getNoticeType", method = RequestMethod.POST)
	@ResponseBody
	public ResultVo getNoticeType() {
		try {
			return ResultUtil.success((Serializable) this.noticeTypeService.listAll());
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}

}